package com.wkr.service;

import com.wkr.bean.PageBean;
import com.wkr.bean.product;
import com.wkr.dao.testDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class testService {

    @Autowired
    testDao td;


    public int getCount() {
        return td.getAll();
    }

    public void save(product p) {
        td.save(p);
    }

    public PageBean find(int currentPage, int MaxSize) {
        PageBean pageBean = new PageBean();
        int totalRecord = td.getAll();
        int startIndex = (currentPage - 1) * MaxSize;
        List<product> items = td.getItems(startIndex, MaxSize);
        int pageSize = MaxSize;
        int totalPage = totalRecord / MaxSize + 1;
        pageBean.setCurrentPage(currentPage);
        pageBean.setTotalRecord(totalRecord);
        pageBean.setPageSize(pageSize);
        pageBean.setItems(items);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }

    public product findone() {
       return td.findone();
    }
}
